import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { gold, green, purple, red } from '@ant-design/colors'

let colors = ''
purple.forEach((color, index) => {
  colors += `--tov-color-primary--${index + 1}:${color};\n`
})
colors += '\n'
green.forEach((color, index) => {
  colors += `--tov-color-success--${index + 1}:${color};\n`
})
colors += '\n'
gold.forEach((color, index) => {
  colors += `--tov-color-warning--${index + 1}:${color};\n`
})
colors += '\n'
red.forEach((color, index) => {
  colors += `--tov-color-error--${index + 1}:${color};\n`
})

const baseURL = fileURLToPath(new URL('../', import.meta.url))
const cssFile = path.resolve(baseURL, 'packages/tov-ui/src/style/theme/colors.less')
colors = `:root{\n${colors}}`
fs.writeFile(cssFile, colors, 'utf-8', (err) => {
  if (err)
    console.error(err)
  else
    console.log('文件写入成功！')
})
